<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport"
	content="initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="深圳一卡通" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title></title>
<link href="/css/common.css" type="text/css" rel="stylesheet" />
<link href="/css/index.css" type="text/css" rel="stylesheet" />
<link href="/css/icons.css" type="text/css" rel="stylesheet" />
<link href="/css/product.css" type="text/css" rel="stylesheet" />
<link href="/css/ucenter.css" type="text/css" rel="stylesheet" />
<link href="/css/add2home.css" type="text/css" rel="stylesheet" />

<script src="/js/jquery.js" type="text/javascript"></script>
<script src="/js/caichong_common.js" type="text/javascript"></script>
<script src="/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="/js/jquery.blackbox.js" type="text/javascript"></script>

<link href="/css/blackbox.css" rel="stylesheet" />


</head>
<body>
	<div id="main">

		<header class="main-header">
			<h1>
				<a href="/" title="">菜虫网</a>
			</h1>
			<div class="list-head-title">
				<h2>我的订单</h2>
			</div>
			<div class="top-shortcuts">
				<ul>
					<li class="ucenter"><a href="/ucenter/index.aspx">用户中心</a></li>
					<li class="cates"><a href="/categories.aspx">全部分类</a></li>
					<li class="cart" id="shoppingcart"><a href="/shopcart.aspx">购物车</a></li>
				</ul>
			</div>
		</header>


		<header class="order-filter">
			<a href="javascript:void(0)" id="waitPay" data-state="10">待处理</a> <a
				href="javascript:void(0)" id="waitPick" data-state="20">待收货</a> <a
				href="javascript:void(0)" id="finlyed" data-state="30">已经完成</a>
		</header>
		<form>
			<div class="orders-search">
				<input type="text" name="keyword" placeholder="请输入订单编号或商品名称"
					value="" id="keyword" /> <input type="submit" value="搜索"
					id="search" />
			</div>
		</form>

		<section class="orders-list"></section>
		<section id="loading">
			<img src="/images/loading.gif" />
		</section>

		<script>
			(function() {

				var state = parseInt('10'), pageindex = 1, pagesize = 20, isLoading = false, keyword = $(
						"#keyword").val();
				$("#empty").hide();
				var PayEvent = function() {
					$(".orders-pay").on("click", function(e) {
						e.preventDefault();
						var orderid = $(this).data("orderid");
						Pay(orderid);

					})
				}
				
			function LoadData() {
					$("#loading").show()
					isLoading = true;
					$.get("/orders/getOrderList?" + "pageindex=" + pageindex + "&pagesize=" + pagesize,
						function(data) {
							if (data.totalRow > 0) {
								for ( var i in data.list) {
									var item = data.list[i];
									//alert( item.id);
									var dom = '<dl id="order_' + item.id + '"><dt>订单编号：<a href="'
											+ baseuri
											+ 'ucenter/orderdetail.aspx?orderid='
											+ item.id
											+ '">'
											+ item.id
											+ '</a>&emsp;'
											+ item.create_time
											+ '</dt>';
									for ( var x in item.OrderProductVariants) {
										var product = item.OrderProductVariants[x];
										var dl = '<dd>'
												+ '<div class="goods-img">'
												+ '    <a href="'
												+ baseuri
												+ 'products.aspx?productid='
												+ product.ProductId
												+ '">'
												+ '        <img src="' + product.ImageUrl + '" /></a>'
												+ '</div>'
												+ '<div class="orders-details">'
												+ '    <p><a href="'
												+ baseuri
												+ 'products.aspx?productid='
												+ product.ProductId
												+ '">'
												+ product.Name
												+ '<span>('
												+ product.Sku
												+ ')</span></a></p>'
												+ '    <p><span class="orders-money"><b>'
												+ product.UnitPriceInclTax
												+ '</b> <i>×</i>'
												+ product.Quantity
												+ '</span></p>'
												+ '</div></dd>';
										dom += dl;
									}

									dom += '<dd><div style="text-align: right;" class="orders-details">'
											+ '<p><span class="orders-money">订单金额：<b>'
											+ item.all_price
											+ '</b>('
											+ item.PaymentMethodName
											+ ')</span></p>'
											+ '<p class="orders-btn">';

									if (item.OrderStatusId == '10'
											&& item.OrderPayStatu == parseInt('10')) {

										dom += '<a href="/GoPay.aspx?orderid='
												+ item.OrderId
												+ '" class="orders-pay" data-orderid="'
												+ item.OrderId
												+ '">付款</a>';

										if (item.OrderPayStatu != parseInt('30'))
											dom += '<a href="javascript:ChangeOrder('
													+ item.OrderId
													+ ');" data-orderid="'
													+ item.OrderId
													+ '">取消订单</a>';
									}
									if (item.OrderStatusId == '20') {
										dom += '<a href="javascript:void(0);" data-orderid="'
												+ item.OrderId
												+ '">确认收货</a>'
									}
									if (item.OrderStatusId == '30') {
										dom += '<a href="javascript:void(0);" data-orderid="'
												+ item.OrderId
												+ '">查看物流</a>';
									}

									dom += '</p></div></dd></dl>'
									$(".orders-list").append(dom);

								}
								pageindex++;
								$("#loading").hide();
								isLoading = false;
							} else if (data.Code === 102) {
								isLoading = true;
								$("#loading").hide();
								if (pageindex == 0) {
									var empty = '<dl><dt>没有订单</dt></dl>';
									$(".orders-list").append(empty);
								}
							} else {
								isLoading = false;
							}
						})

				}
				function onScroll(event) {
					// Only check when we're not still waiting for data.
					if (!isLoading) {
						// Check if we're within 100 pixels of the bottom edge of the broser window.
						var closeToBottom = ($(window).scrollTop()
								+ $(window).height() > $(document).height() - 100);
						if (closeToBottom) {
							LoadData();
						}
					}
				}
				;
				LoadData();
				$(window).scroll(onScroll);
				$("#search").click(function(e) {
					e.preventDefault();
					keyword = $("#keyword").val();
					$(".orders-list").empty();
					pageindex = 0;
					LoadData();
				})

				$("#waitPick,#waitPay,#finlyed").click(function(e) {
					e.preventDefault();
					state = $(this).data("state");
					keyword = "";
					$(".order-filter a").removeClass("order-filter-cur");
					$(this).addClass("order-filter-cur");
					$(".orders-list").empty();
					pageindex = 1;
					LoadData();
				});

				$(".orders-pay").on("click", function(e) {
					e.preventDefault();
					var orderid = $(this).data("orderid");
					console.log(orderid);

				})

				$(document).ready(function() {
					$(".order-filter a").each(function() {
						if ($(this).data("state") === state) {
							$(this).addClass("order-filter-cur");
						}
					})

				});

				function Pay(orderId) {
					$.get(
									baseuri + "Service/order.asmx/Pay?orderId="
											+ orderId,
									function(result) {
										if (result.Msg === 'Ok') {
											var data = result.Obj.api, pk = data["package"];
											pk["timestamp"] = getTimeStamp();
											var pck = getPackage(pk["body"],
													pk["notify_url"],
													pk["out_trade_no"],
													pk["partner"],
													pk["total_fee"],
													data["partnerkey"]);
											var paySign = getSign(
													data["appid"],
													data["appkey"],
													data["noncestr"],
													pk["timestamp"], pck);
											var params = {
												"appId" : data["appid"],
												"timeStamp" : pk["timestamp"],
												"nonceStr" : data["noncestr"],
												"package" : pck,
												"signType" : "SHA1",
												"paySign" : paySign
											};

											//alert(pck);
											//alert(paySign); 
											//alert(params.appId);
											WeixinJSBridge
													.invoke(
															'getBrandWCPayRequest',
															params,
															function(res) {
																if (res.err_msg == "get_brand_wcpay_request:ok") {
																	Message("付款成功.正在跳转...");
																	setTimeout(
																			function() {
																				window.location.href = baseuri
																						+ "WXsdk/orders.aspx?type=30";
																				;
																			},
																			200)

																} else {
																	Message("付款未成功.正在跳转订单页...")
																	setTimeout(
																			function() {
																				window.location.href = baseuri
																						+ "WXsdk/orders.aspx?type=10";
																				;
																			},
																			200)
																}
															});
										}
									})
				}

			})();
			function ChangeOrder(orderId) {

				var box = new BlackBox();
				box.confirm("添加购物车成功,", function(data) {
					if (data) {
						$.get(baseuri
								+ "Service/Order.asmx/ChangedOrder?orderId="
								+ orderId, function(result) {
							if (result.Msg === 'Ok') {
								Message("订单已取消");
								$("#order_" + orderId).remove();
							}
						})
						return false;
					} else {

					}
				}, {
					title : '你确定要删除这件商品么?',
					value : '确定',
					channel : '放弃'
				})
			}
		</script>




		<!--固定搜索-->
		<div id="bottom-sch" class="sch-box search-fixed">
			<form id="f2" action="/productlist.aspx"
				method="get">
				<div class="search layout mt20 mb20">
					<input type="search" placeholder="奇异果" id="main-sch-bottom"
						name="keyword" /> <input type="submit" id="sch-submit-bottom"
						class="s-submit" value="" />
				</div>
			</form>
		</div>
		<!--固定搜索end-->

		<!--浮动按钮-->
		<div class="f-menu">
			<div class="floatmenu">
				<i class="menuinner"></i>
			</div>
			<div class="circle hide">
				<div class="c-ucenter">
					<a href="/ucenter/index.aspx"
						class="c-ucLink"></a>
				</div>
				<div class="c-sch c-menu">
					<a href="/productlist.aspx"
						class="c-schlink"></a>
				</div>
				<div class="c-order c-menu">
					<a href="/ucenter/orders.aspx"
						class="c-orderlink"></a>
				</div>
				<div class="c-service  c-menu">
					<a href="javascript:void(0)" class="c-servicelink"></a>
				</div>
				<div class="c-shopcart c-menu">
					<a href="/shopcart.aspx"
						class="c-cartlink"></a>
				</div>
			</div>
		</div>
		<!--浮动按钮end-->
		<footer class="bottom">
			<div class="bottom-shortcuts layout">
				<ul>
					<li><i class="login"></i><a
						href="/logout.aspx">退出</a></li>
					<li class="l-spacing"></li>

					<li class="fr"><i class="cart"></i><a
						href="/ShopCart.aspx">购物车</a></li>
				</ul>
			</div>
			<div class="version">
				<span id="backtotop"><a href="javascript:void(0);"><i
						class="gray">▲</i>返回顶部</a></span>
				<p>
					<span><a href="/">标准版</a> <a
						href="http://www.caichongwang.com/?from=wap">电脑版</a> </span>
				</p>
				<p class="copy">
					菜虫网—国内最专业的生鲜产品网上商城<br /> 经营许可备案号：粤B2-20120403<br /> 菜虫网版权所有
				</p>
			</div>
		</footer>

	</div>
</body>
</html>
